package com.cong.security.app.social;

import java.util.HashMap;
import java.util.Map;
import com.cong.security.core.social.MySocialUser;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

public class MyJwtTokenEnhancer implements TokenEnhancer {

	@Override
	public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
		Map<String, Object> map = new HashMap<>();
		MySocialUser mySocialUser = (MySocialUser) authentication.getPrincipal();
		// 从数据库中根据手机号之类信息查询出
		map.put("userId", mySocialUser.getId());
		((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(map);
		return accessToken;
	}
}
